package com.studentexam.student.service.impl;

import com.studentexam.student.dao.AnswerMapper;
import com.studentexam.student.dao.PersonMapper;
import com.studentexam.student.dao.StudentMapper;
import com.studentexam.student.model.Student;
import com.studentexam.student.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class StudentServiceImpl implements StudentService{

    @Autowired
    private StudentMapper studentMapper;
    @Autowired
    private AnswerMapper answerMapper;


    @Override
    public int addStudent(Student student) {
        int returnInt=studentMapper.insertStudent(student);

        return returnInt;
    }

    @Override
    public int updateStudent(Student student) {
        int isUpdate=0;
        try{
            isUpdate=studentMapper.updateStudent(student);
        }catch (Exception e){
            isUpdate=-1;
            System.out.println("更新角色时执行sql报错原因为:"+e.getMessage());
        }
        return isUpdate;
    }

    @Override
    public int delStudent(int studentid) {
        int returnDel=0;
        try {
            if (answerMapper.getStudentCount(studentid)< 1) {
                returnDel = studentMapper.delStudent(studentid);
            }
        }catch (Exception e){
            returnDel=-1;
            System.out.println("删除失败原因为："+e.getMessage());
        }
        return returnDel;
    }

    @Override
    public List<Student> getByStudentid(int studentid) {
        List<Student> studentList=studentMapper.getByStudentid(studentid);
        return studentList;
    }

    @Override
    public List<Student> getAllStudent(Student student){
        List<Student> studentList = studentMapper.getAllStudent(student);
        return studentList;
    }
}
